package com.youi.web;

import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.google.common.collect.Maps;
import com.youi.common.Common;
import com.youi.common.DelStatus;
import com.youi.common.SessionKey;
import com.youi.entity.Plamtwithdraw;
import com.youi.entity.Plamtwithdrawdetail;
import com.youi.entity.Sysuser;
import com.youi.entity.Tremittance;
import com.youi.entity.Userorder;
import com.youi.entity.vo.ExportPlatformOrderVO;
import com.youi.entity.vo.ExportPlatformWithdrawVO;
import com.youi.exception.BusinessException;
import com.youi.manage.HttpRequestManage;
import com.youi.manage.HttpSessionManage;
import com.youi.model.Platformwithdrawstat;
import com.youi.service.OrderprofitdetailService;
import com.youi.service.PlamtwithdrawService;
import com.youi.service.PlamtwithdrawdetailService;
import com.youi.service.PlatformwithdrawstatService;
import com.youi.service.TremittanceService;
import com.youi.service.UserorderService;
import com.youi.util.CommonInfoUtil;
import com.youi.util.DateUtil;
import com.youi.util.EasyPoiUtil;
import com.youi.util.ExcelStyleUtil;
import com.youi.util.JsonUtil;
import com.youi.util.ObjectUtil;
import com.youi.util.Page;
import com.youi.util.SmsUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 平台提现信息控制层
 *
 * @author Administrator
 */
@Controller
public class PlamtwithdrawController extends HttpRequestManage {

    @Autowired
    private PlamtwithdrawService plamtwithdrawService;
    @Autowired
    private UserorderService userorderService;
    @Autowired
    private OrderprofitdetailService orderprofitdetailService;
    @Autowired
    private PlatformwithdrawstatService platformwithdrawstatService;
    @Autowired
    private TremittanceService tremittanceService;
    @Autowired
    private PlamtwithdrawdetailService plamtwithdrawdetailService;


    /**
     * I-101
     * 查询平台申请提现列表
     *
     * @param modelMap
     * @param request
     * @return
     * @throws BusinessException
     * @throws ParseException
     */
    @ResponseBody
    @RequestMapping("sysUserGetInfo/getPlatformUserorder")
    public String getPlatformUserOrder(ModelMap modelMap, HttpServletRequest request) throws BusinessException, ParseException {
        Integer pageIndex = optInteger("pageIndex", request, 1);
        Integer pageNum = optInteger("pageNum", request, 10);
        //查询参数
        String topOrderNo = optString("topOrderNo", request);
        String orderNo = optString("orderNo", request);
        String start = optString("start", request);
        String end = optString("end", request);
        Integer status = optInteger(Common.STATUS, request);
        String des = optString("des", request, Common.DESC);

        Map<String, Object> prams = Maps.newHashMap();
        prams.put(Common.DELSTATUS, DelStatus.NODEL);
        prams.put(Common.STATUS, Arrays.asList(1, 2, 3, 4, 5));
        prams.put("refund", -1);
        if (StringUtils.isNotBlank(topOrderNo)) {
            prams.put("topOrderNo", topOrderNo);
        }
        if (StringUtils.isNotBlank(orderNo)) {
            prams.put("orderNo", orderNo);
        }
        if (status != null) {
            if (status == 6) {
                prams.put("platformStatus", Arrays.asList(1, 4));
            } else {
                prams.put("platformStatus", status);
            }
        }

        Map<String, Object> sortPram = Maps.newHashMap();
        sortPram.put(Common.ID, des);

        Map<String, Object> startTimeMap = null;
        if (start != null) {
            startTimeMap = Maps.newHashMap();
            startTimeMap.put("gmtOrder", DateUtil.simpdfyMdHms.parse(start));
        }
        Map<String, Object> endTimeMap = null;
        if (end != null) {
            endTimeMap = Maps.newHashMap();
            endTimeMap.put("gmtOrder", DateUtil.simpdfyMdHms.parse(end));
        }

        List<Userorder> userOrderList = userorderService.getByParamsList(prams, null, sortPram,
                (pageIndex - 1) * pageNum, pageNum, startTimeMap, endTimeMap);
        if (CollectionUtils.isEmpty(userOrderList)) {
            return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
        }
        Integer pageCount = userorderService.getCountByParamss(prams, null, startTimeMap, endTimeMap);
        modelMap.put(CommonInfoUtil.PAGECOUNT, Page.getCount(pageCount, pageNum));
        modelMap.put(CommonInfoUtil.PAGEINDEX, pageIndex);
        modelMap.put(CommonInfoUtil.ALLCOUINT, pageCount);
        modelMap.put(CommonInfoUtil.DATA, userOrderList);
        plamtwithdrawService.getWithdrawUserOrderMsg(userOrderList);
        return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成", modelMap);
    }

    /**
     * I-105
     * 查询平台申请提现统计
     *
     * @param modelMap
     * @param request
     * @return
     * @throws BusinessException
     * @throws ParseException
     */
    @ResponseBody
    @RequestMapping("sysUserGetInfo/getPlatformUserorderStats")
    public String getPlatformUserorderStats(ModelMap modelMap, HttpServletRequest request) throws BusinessException, ParseException {
        Integer status = optInteger(Common.STATUS, request);
        String start = optString("start", request);
        String end = optString("end", request);
        String topOrderNo = optString("topOrderNo", request);
        String orderNo = optString("orderNo", request);
        Platformwithdrawstat platformwithdrawstat = platformwithdrawstatService.getUserorderstatByParamss(status, start, end, topOrderNo, orderNo);
        return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成", platformwithdrawstat);
    }

    /**
     * I-106
     * 导出平台提现申请excel
     */
    @Deprecated
    @ResponseBody
    @RequestMapping("toExcelPlatformUserorder")
    public String toExcelPlatformUserorder(ModelMap modelMap, HttpServletRequest request) throws BusinessException, ParseException {
        Integer status = optInteger(Common.STATUS, request);
        String des = optString("des", request, Common.DESC);
        String pms = optString("pms", request);
        String start = optString("start", request);
        String end = optString("end", request);
        Map<String, Object> prams = new HashMap<String, Object>();
        prams.put(Common.DELSTATUS, DelStatus.NODEL);
        prams.put(Common.STATUS, Arrays.asList(1, 2, 3, 4, 5));
        if (status != null) {
            prams.put("platformStatus", status);
        }
        Map<String, Object> sortPram = new HashMap<String, Object>();
        sortPram.put(Common.ID, des);
        Map<String, Object> searchPram = null;
        if (pms != null && pms.length() > 0) {
            searchPram = new HashMap<String, Object>();
        }
        Map<String, Object> startTime = null;
        if (start != null) {
            startTime = new HashMap<String, Object>();
            startTime.put("gmtOrder", DateUtil.simpdfyMdHms.parse(start));
        }
        Map<String, Object> endTime = null;
        if (end != null) {
            endTime = new HashMap<String, Object>();
            endTime.put("gmtOrder", DateUtil.simpdfyMdHms.parse(end));
        }
        List<Userorder> userorderList = userorderService.getByParamsAll(prams, searchPram, sortPram, startTime, endTime);
        if (userorderList == null || userorderList.size() == 0) {
            return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
        }
        plamtwithdrawService.getWithdrawUserOrderMsg(userorderList);
        plamtwithdrawService.toExcelPlatformUserorder(request, userorderList);
        modelMap.put(CommonInfoUtil.JSONCODE, CommonInfoUtil.SUCCESS);
        modelMap.put(CommonInfoUtil.JSONMSG, "操作成功");
        return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成", modelMap);
    }


    /**
     * 导出平台可提现订单
     */
    @ResponseBody
    @RequestMapping(value = "sysUserGetInfo/exportPlatformOrder", produces = "application/json")
    public void exportPlatformOrder(@RequestBody Map<String, Object> param, HttpServletRequest request, HttpServletResponse response) throws BusinessException, ParseException {
        List<ExportPlatformOrderVO> exportOrderList = userorderService.getExportPlatformOrder(param);
        if (CollectionUtils.isEmpty(exportOrderList)) {
            throw new BusinessException(-1, "没有要导出的数据");
        }

        try {
            String fileName = "订单" + DateUtil.simpyMdHHmmss.format(new Date());
            ExportParams exportParams = new ExportParams(null, "订单", ExcelType.XSSF);
            exportParams.setStyle(ExcelStyleUtil.class);

            EasyPoiUtil.exportExcel(fileName, exportParams, ExportPlatformOrderVO.class, exportOrderList, request, response);
        } catch (Exception ex) {
            throw new BusinessException(-1, "导出数据失败");
        }
    }

    /**
     * I-107
     * 生成提现申请单佣金弹框提示
     */
    @ResponseBody
    @RequestMapping("sysUserGetInfo/platformUserorderTips")
    public String platformUserorderTips(ModelMap modelMap, HttpServletRequest request) throws BusinessException {
        String ids = getString("ids", request);
        List<Long> idsList = ObjectUtil.getIdListByIds(ids);
        if (idsList == null || idsList.size() == 0) {
            return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "ids参数错误");
        }
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(Common.DELSTATUS, DelStatus.NODEL);
        params.put(Common.ID, idsList);
        List<Userorder> userorderList = userorderService.getByParams(params);
        if (userorderList == null || userorderList.size() == 0) {
            return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
        }
        plamtwithdrawService.getWithdrawUserOrderMsg(userorderList);
        Integer count = 0;
        Double allProfit = 0.00;
        Double amount = 0.00;
        for (Userorder userorder : userorderList) {
            if (userorder.getPlatformSum() != null) {
                allProfit += userorder.getPlatformSum();
            }
            if (userorder.getAmount() != null) {
                amount += userorder.getAmount();
            }
            count++;
        }
        modelMap.put("count", count);
        modelMap.put("allProfit", allProfit);
        modelMap.put("amount", amount);
        return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成", modelMap);
    }

    /**
     * I-108
     * 生成平台提现申请单
     */
    @ResponseBody
    @RequestMapping("sysUserGetInfo/addPlamtwithdraw")
    public String addPlamtwithdraw(ModelMap modelMap, HttpServletRequest request) throws BusinessException {
        Sysuser sysuser = (Sysuser) HttpSessionManage.getAttribute(request, SessionKey.SYSUSER);
        DecimalFormat doubleFomat = new DecimalFormat("0.00");
        String ids = getString("ids", request);
        List<Long> idsList = ObjectUtil.getIdListByIds(ids);
        if (idsList == null || idsList.size() == 0) {
            return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "ids参数错误");
        }
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(Common.DELSTATUS, DelStatus.NODEL);
        params.put(Common.ID, idsList);
        List<Userorder> userorderList = userorderService.getByParams(params);
        if (userorderList == null || userorderList.size() == 0) {
            return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
        }
        plamtwithdrawService.getWithdrawUserOrderMsg(userorderList);
        for (Userorder userorder : userorderList) {
            if (userorder.getPlatformStatus() != 1 && userorder.getPlatformStatus() != 4) {
                return JsonUtil.toJson(CommonInfoUtil.NOPERMISSIONS, "订单非可提现状态无法申请提现");
            }
        }
        String withdrawNo = "PTTX" + DateUtil.simpyMd.format(new Date()) + SmsUtil.getRandom(5);
        String dateNo = DateUtil.simpyMd.format(new Date());
        Plamtwithdraw plamtwithdraw = new Plamtwithdraw(sysuser.getId(), withdrawNo, dateNo);
        plamtwithdrawService.saveOrUpdate(plamtwithdraw);
        Double amount = 0.00;//订单总额
        Double serviceCharge = 0.00;//手续费
        Double allProfitAmount = 0.00;//平台总分润(加上手续费)
        Double platAmount = 0.00;//平台分润
        Double realProfitAmount = 0.00;//平台真实分润(除去手续费)
        Double merchantAmount = 0.00;//供应商分润
        Double leaderAmount = 0.00;//团长总分润
        for (Userorder userorder : userorderList) {
            userorder.setPlatformStatus(2);
            Plamtwithdrawdetail plamtwithdrawdetail = new Plamtwithdrawdetail(plamtwithdraw.getId());
            plamtwithdrawdetail.setWithdrawNo(plamtwithdraw.getWithdrawNo());
            plamtwithdrawdetail.setOrderNo(userorder.getOrderNo());
            plamtwithdrawdetail.setOrderAmount(userorder.getAmount());
            plamtwithdrawdetail.setStatus(userorder.getPlatformStatus());
            if (userorder.getMerchantRatio() != null) {
                plamtwithdrawdetail.setMerchantRatio(userorder.getMerchantRatio());
            }
            if (userorder.getMerchantAmount() != null) {
                plamtwithdrawdetail.setMerchantAmount(userorder.getMerchantAmount());
            }
            if (userorder.getPlatformRatio() != null) {
                plamtwithdrawdetail.setPlatformRatio(userorder.getPlatformRatio());
            }
            if (userorder.getPlatformAmount() != null) {
                plamtwithdrawdetail.setPlatformAmount(userorder.getPlatformAmount());
            }
            if (userorder.getLeaderRatio() != null) {
                plamtwithdrawdetail.setLeaderRatio(userorder.getLeaderRatio());
            }
            if (userorder.getLeaderAmount() != null) {
                plamtwithdrawdetail.setLeaderAmount(userorder.getLeaderAmount());
            }
            if (userorder.getPlatformSum() != null) {
                plamtwithdrawdetail.setPlatformSum(userorder.getPlatformSum());
            }
            amount += userorder.getAmount();
            if (userorder.getServiceCharge() != null) {
                serviceCharge += userorder.getServiceCharge();
            }
            if (userorder.getPlatformSum() != null) {
                realProfitAmount += userorder.getPlatformSum();
            }
            if (userorder.getPlatformAmount() != null) {
                platAmount += userorder.getPlatformAmount();
            }
            if (userorder.getMerchantAmount() != null) {
                merchantAmount += userorder.getMerchantAmount();
            }
            if (userorder.getLeaderAmount() != null) {
                leaderAmount += userorder.getLeaderAmount();
            }
            plamtwithdrawdetailService.saveOrUpdate(plamtwithdrawdetail);
        }
        plamtwithdraw.setOrderCount(userorderList.size());
        plamtwithdraw.setOrderAmount(ObjectUtil.sciCal(amount, 2));
        plamtwithdraw.setServiceCharge(ObjectUtil.sciCal(serviceCharge, 2));
        plamtwithdraw.setRealProfitAmount(ObjectUtil.sciCal(realProfitAmount, 2));
        plamtwithdraw.setAllProfitAmount(ObjectUtil.sciCal(platAmount, 2));
        plamtwithdraw.setMerchantAmount(ObjectUtil.sciCal(merchantAmount, 2));
        plamtwithdraw.setLeaderAmount(ObjectUtil.sciCal(leaderAmount, 2));
        plamtwithdrawService.saveOrUpdate(plamtwithdraw);
        userorderService.saveOrUpdateAll(userorderList);
        return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成", modelMap);
    }


    /**
     * I-109
     * 查询平台提现信息列表
     */
    @ResponseBody
    @RequestMapping("sysUserGetInfo/getPlamtwithdraw")
    public String getPlamtWithdraw(ModelMap modelMap, HttpServletRequest request) throws BusinessException, ParseException {
        Integer pageIndex = optInteger("pageIndex", request, 1);
        Integer pageNum = optInteger("pageNum", request, 10);
        //查询参数
        String withdrawNo = optString("withdrawNo", request);
        String dateNo = optString("dateNo", request);
        Date start = optDate("start", request, "yyyy-MM-dd HH:mm:ss");
        Date end = optDate("end", request, "yyyy-MM-dd HH:mm:ss");
        Integer status = optInteger(Common.STATUS, request);
        String des = optString("des", request, Common.DESC);

        Map<String, Object> prams = Maps.newHashMap();
        prams.put(Common.DELSTATUS, DelStatus.NODEL);
        if (status != null) {
            prams.put(Common.STATUS, status);
        }
        if (Strings.isNotBlank(withdrawNo)) {
            prams.put("withdrawNo", withdrawNo);
        }
        if (Strings.isNotBlank(dateNo)) {
            prams.put("dateNo", dateNo);
        }

        Map<String, Object> sortPram = Maps.newHashMap();
        sortPram.put(Common.ID, des);

        Map<String, Object> startTime = null;
        if (start != null) {
            startTime = Maps.newHashMap();
            startTime.put(Common.GMTCREATED, start);
        }
        Map<String, Object> endTime = null;
        if (end != null) {
            endTime = Maps.newHashMap();
            endTime.put(Common.GMTCREATED, end);
        }

        List<Plamtwithdraw> withdrawList = plamtwithdrawService.getByParamsList(prams, null, sortPram,
                (pageIndex - 1) * pageNum, pageNum, startTime, endTime);
        if (CollectionUtils.isEmpty(withdrawList)) {
            return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
        }
        Integer pageCount = plamtwithdrawService.getCountByParamss(prams, null, startTime, endTime);
        modelMap.put(CommonInfoUtil.PAGECOUNT, Page.getCount(pageCount, pageNum));
        modelMap.put(CommonInfoUtil.PAGEINDEX, pageIndex);
        modelMap.put(CommonInfoUtil.ALLCOUINT, pageCount);
        modelMap.put(CommonInfoUtil.DATA, withdrawList);
        plamtwithdrawService.getPlamtwithdraw(withdrawList);
        return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成", modelMap);
    }

    /**
     * I-110
     * 查询平台提现信息详情
     */
    @ResponseBody
    @RequestMapping("sysUserGetInfo/getPlamtwithdrawById")
    public String getPlamtwithdrawById(ModelMap modelMap, HttpServletRequest request) throws BusinessException {
        Long id = getLong("id", request);
        Plamtwithdraw plamtwithdraw = plamtwithdrawService.get(id);
        if (plamtwithdraw == null) {
            return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
        }
        plamtwithdrawService.getPlamtwithdraw(plamtwithdraw);
        return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成", plamtwithdraw);//jsonObject	json对象
    }

    /**
     * I-111
     * 导出平台度提现申请excel
     *
     * @param modelMap
     * @param request
     * @return
     * @throws BusinessException
     * @throws ParseException
     */
    @Deprecated
    @ResponseBody
    @RequestMapping("toExcelPlamtwithdraw")
    public String toExcelPlamtwithdraw(ModelMap modelMap, HttpServletRequest request) throws BusinessException, ParseException {
        Integer status = optInteger(Common.STATUS, request);
        String des = optString("des", request, Common.DESC);
        String pms = optString("pms", request);
        String dateNo = optString("dateNo", request);
        Date start = optDate("start", request, "yyyy-MM-dd HH:mm:ss");
        Date end = optDate("end", request, "yyyy-MM-dd HH:mm:ss");
        Map<String, Object> prams = new HashMap<String, Object>();
        prams.put(Common.DELSTATUS, DelStatus.NODEL);
        if (status != null) {
            prams.put(Common.STATUS, status);
        }
        if (dateNo != null && dateNo.trim().length() > 0) {
            prams.put("dateNo", dateNo);
        }
        Map<String, Object> sortPram = new HashMap<String, Object>();
        sortPram.put(Common.ID, des);
        Map<String, Object> searchPram = null;
        if (pms != null) {
            searchPram = new HashMap<String, Object>();
        }
        Map<String, Object> startTime = null;
        if (start != null) {
            startTime = new HashMap<String, Object>();
            startTime.put(Common.GMTCREATED, start);
        }
        Map<String, Object> endTime = null;
        if (end != null) {
            endTime = new HashMap<String, Object>();
            endTime.put(Common.GMTCREATED, end);
        }
        List<Plamtwithdraw> plamtwithdrawList = plamtwithdrawService.getByParamsAll(prams, null, sortPram, startTime, endTime);
        if (plamtwithdrawList == null || plamtwithdrawList.size() == 0) {
            return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
        }
        plamtwithdrawService.getPlamtwithdraw(plamtwithdrawList);
        plamtwithdrawService.toExcelPlamtwithdraw(request, plamtwithdrawList);
        modelMap.put(CommonInfoUtil.JSONCODE, CommonInfoUtil.SUCCESS);
        modelMap.put(CommonInfoUtil.JSONMSG, "操作成功");
        return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成", modelMap);
    }


    /**
     * 导出平台提现单
     *
     * @param param
     * @param request
     * @param response
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "sysUserGetInfo/exportPlatformWithdraw", produces = "application/json")
    public void exportPlatformWithdraw(@RequestBody Map<String, Object> param, HttpServletRequest request, HttpServletResponse response) throws Exception {
        //根据条件查询全部数据,不分页
        List<ExportPlatformWithdrawVO> exportOrderList = plamtwithdrawService.listExportData(param);
        if (CollectionUtils.isEmpty(exportOrderList)) {
            throw new BusinessException(-1, "没有要导出的数据");
        }

        try {
            String fileName = "平台提现信息" + DateUtil.simpyMdHHmmss.format(new Date());
            ExportParams exportParams = new ExportParams(null, "平台提现", ExcelType.XSSF);
            exportParams.setStyle(ExcelStyleUtil.class);

            EasyPoiUtil.exportExcel(fileName, exportParams, ExportPlatformWithdrawVO.class, exportOrderList, request, response);
        } catch (Exception ex) {
            throw new BusinessException(-1, "导出数据失败");
        }
    }

    /**
     * I-112
     * 审核平台提现申请单
     */
    @ResponseBody
    @RequestMapping("sysUserGetInfo/applyPlamtwithdraw")
    public String applyPlamtwithdraw(ModelMap modelMap, HttpServletRequest request) throws BusinessException {
        Sysuser sysuser = (Sysuser) HttpSessionManage.getAttribute(request, SessionKey.SYSUSER);
        String ids = getString("ids", request);
        Integer status = getInteger(Common.STATUS, request);
        String applyIdea = optString("applyIdea", request);
        List<Long> idsList = ObjectUtil.getIdListByIds(ids);
        if (idsList == null || idsList.size() == 0) {
            return JsonUtil.toJson(CommonInfoUtil.PARAMERROR, "ids参数错误");
        }
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(Common.DELSTATUS, DelStatus.NODEL);
        params.put(Common.ID, idsList);
        List<Plamtwithdraw> plamtwithdrawList = plamtwithdrawService.getByParams(params);
        if (plamtwithdrawList == null || plamtwithdrawList.size() == 0) {
            return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
        }
        plamtwithdrawService.getPlamtwithdraw(plamtwithdrawList);
        for (Plamtwithdraw plamtwithdraw : plamtwithdrawList) {
            if (plamtwithdraw.getStatus() != 0) {
                return JsonUtil.toJson(CommonInfoUtil.NOPERMISSIONS, "提现申请非审核状态无法审核");
            }
            if (status == 1) {
                Tremittance tremittance = new Tremittance(plamtwithdraw.getCreatorId(), 1, plamtwithdraw.getWithdrawNo(), plamtwithdraw.getOrderAmount(), null, "美宜佳健康商城", 0);
                tremittance.setProfitRatio(15.00);
                tremittanceService.saveOrUpdate(tremittance);
            } else if (status == -1) {
                List<Plamtwithdrawdetail> plamtwithdrawdetailList = plamtwithdraw.getPlamtwithdrawdetailList();
                if (plamtwithdrawdetailList != null && plamtwithdrawdetailList.size() > 0) {
                    for (Plamtwithdrawdetail plamtwithdrawdetail : plamtwithdrawdetailList) {
                        params = new HashMap<String, Object>();
                        params.put(Common.DELSTATUS, DelStatus.NODEL);
                        params.put("orderNo", plamtwithdrawdetail.getOrderNo());
                        Userorder userorder = userorderService.getByParam(params);
                        if (userorder != null) {
                            userorder.setPlatformStatus(4);
                            userorderService.saveOrUpdate(userorder);
                        }
                    }
                }
            }
            if (applyIdea != null && applyIdea.trim().length() > 0) {
                plamtwithdraw.setApplyIdea(applyIdea);
            }
            plamtwithdraw.setAuditorId(sysuser.getId());
            plamtwithdraw.setGmtApply(new Date());
            plamtwithdraw.setStatus(status);
            plamtwithdrawService.saveOrUpdate(plamtwithdraw);
        }
        return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成");
    }

    /**
     * I-113
     * 保存平台提现申请备注
     */
    @ResponseBody
    @RequestMapping("sysUserGetInfo/savePlamtwithdrawRemark")
    public String savePlamtwithdrawRemark(ModelMap modelMap, HttpServletRequest request) throws BusinessException {
        Long id = getLong("id", request);
        String remark = optString("remark", request);
        Plamtwithdraw plamtwithdraw = plamtwithdrawService.get(id);
        if (plamtwithdraw == null) {
            return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
        }
        if (remark != null && remark.trim().length() > 0) {
            plamtwithdraw.setRemark(remark);
        }
        plamtwithdrawService.saveOrUpdate(plamtwithdraw);
        return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成", plamtwithdraw);//jsonObject	json对象
    }

    /**
     * 查询所有平台提现信息
     *
     * @param modelMap
     * @param session
     * @return
     */
    @ResponseBody
    @RequestMapping("getAllPlamtwithdraw")
    public String getAllPlamtwithdraw(ModelMap modelMap, HttpServletRequest request) throws BusinessException {
        List<Plamtwithdraw> plamtwithdrawList = plamtwithdrawService.getByParams(null);
        if (plamtwithdrawList == null || plamtwithdrawList.size() == 0) {
            return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
        }
        return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成", plamtwithdrawList);//jsonObjectList	json对象集合
    }
}
